using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using NTTHAO.Web.BL.Product;


namespace NTTHAO.Sites.CommonSite
{
    public class OrderItem
    {
        public int ProductID = 0;
        public int Quantity = 0;

        private OrderItem() { }

        public OrderItem(int productID, int quantity)
        {
            this.ProductID = productID;
            this.Quantity = quantity;
        }

        public bool Equals(OrderItem item)
        {
            return (this.ProductID == item.ProductID);
        }
    }

    public class OrderItemCollection : CollectionBase
    {
        /// <summary>
        /// Initializes a new instance of the OrderItemCollection
        /// class with the default initial capacity.
        /// </summary>
        public OrderItemCollection()
            : base()
        {
        }

        /// <summary>
        /// Adds an item to the OrderItemCollection.
        /// </summary>
        /// <param name="value">The OrderItem to add to the OrderItemCollection.</param>
        /// <returns>The position into which the new element was inserted.</returns>
        public int Add(OrderItem value)
        {
            return List.Add(value);
        }

        /// <summary>
        /// Inserts an item to the OrderItemCollection at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which value should be inserted.</param>
        /// <param name="value">The OrderItem to insert into the OrderItemCollection.</param>
        public void Insert(int index, OrderItem value)
        {
            List.Insert(index, value);
        }

        /// <summary>
        /// Determines the index of a specific item in the OrderItemCollection.
        /// </summary>
        /// <param name="value">The OrderItem to locate in the OrderItemCollection.</param>
        /// <returns>The index of value if found in the list; otherwise, -1.</returns>
        public int IndexOf(OrderItem value)
        {
            if (value == null)
            {
                return -1;
            }
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].Equals(value))
                {
                    return i;
                }
            }
            return -1;
        }

        /// <summary>
        /// Determines whether the OrderItemCollection contains a specific value.
        /// </summary>
        /// <param name="value">The OrderItem to locate in the OrderItemCollection.</param>
        /// <returns>true if the OrderItem is found in the OrderItemCollection; otherwise, false.</returns>
        public bool Contains(OrderItem value)
        {
            return (this.IndexOf(value) >= 0);
        }

        /// <summary>
        /// Copies the elements of the OrderItemCollection to an OrderItem[],
        /// starting at a particular OrderItem[] index.
        /// </summary>
        /// <param name="value">The one-dimensional OrderItem[] that is the destination of the elements
        /// copied from OrderItemCollection. The  OrderItem[] must have zero-based
        /// indexing.</param>
        /// <param name="index">The zero-based index in array at which copying begins.</param>
        public void CopyTo(OrderItem[] value, int index)
        {
            List.CopyTo(value, index);
        }

        /// <summary>
        /// Removes the first occurrence of a specific object from the OrderItemCollection.
        /// </summary>
        /// <param name="value">The OrderItem to remove from the OrderItemCollection.</param>
        public void Remove(OrderItem value)
        {
            List.Remove(value);
        }

        /// <summary>
        /// Get all elements of the OrderItemCollection in one-dimensional OrderItem[].
        /// </summary>
        /// <returns>One-dimensional OrderItem[] contains all elements of the OrderItemCollection.</returns>
        public OrderItem[] ToArray()
        {
            OrderItem[] array = new OrderItem[List.Count];
            List.CopyTo(array, 0);
            return array;
        }

        /// <summary>
        /// Gets or sets the element at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the element to get or set.</param>
        /// <returns>The element at the specified index.</returns>
        public OrderItem this[int index]
        {
            get
            {
                return (OrderItem)List[index];
            }
            set
            {
                List[index] = value;
            }
        }

        /// <summary>
        /// Returns a System.String that represents the current OrderItemCollection.
        /// </summary>
        /// <returns>A System.String that represents the current OrderItemCollection.</returns>
        public override string ToString()
        {
            return "OrderItemCollection";
        }

    }
}
